#include "enemyplane.h"
#include"config.h"
enemyplane::enemyplane()
{
    m_enemy.load(":/picture/enemy1.png");
    boss.load(":/picture/boss.png");

    bossrecorder=0;

    m_x=0;
    m_y=0;

    m_x_boss=0;
    m_y_boss=0;

    //
    m_free=true;
    m_free_boss=true;
    //
    m_rect.setWidth(m_enemy.width());
    m_rect.setHeight(m_enemy.height());
    m_rect.moveTo(m_x,m_y);

    m_rect_boss.setWidth(boss.width());
    m_rect_boss.setHeight(boss.height());
    m_rect_boss.moveTo(m_x,m_y);
    //
    m_speed=enemy_speed;
    m_speed_boss=4;

    //
    hp=1;
    boss_hp=10;
     bossmove=0;
    right=true;
}

void enemyplane::updateposition()
{
    if(m_free==true)
    {
        return;
    }
    else
    {
        m_y+=m_speed;
        m_rect.moveTo(m_x,m_y);
    }
    if(m_y>=Game_HEIGHT)
    {
        m_free=true;
    }

}

void enemyplane::bossupdateposition()
{

    if(m_free_boss==true)
    {
        return;
    }
    else
    {
        bossmove++;
        if(bossmove<5)
        {
            return;
        }
        else
        {
            bossmove=0;
            if(right)
            {
                m_x_boss+=5;
            }
            else
            {
                m_x_boss-=5;
            }
        }

        if(m_x_boss<=0)
        {
            right=true;
        }
        if(m_x_boss>=Game_WIDTH-m_rect_boss.width())
        {
            right=false;
        }

        m_rect_boss.moveTo(m_x_boss,m_y_boss);
    }
}

void enemyplane::bossshot()
{
    //时间间隔
    bossrecorder++;
    //是否发射
    if(bossrecorder<40)
    {
        return;
    }
    else
    {
        bossrecorder=0;
        //子弹是否空闲
        for(int i=0;i<20;i++)
        {
            if(bossbullet[i].m_free_boss)
            {
                bossbullet[i].m_free_boss=false;
                //设置坐标
                bossbullet[i].m_x_boss=m_x_boss+m_rect_boss.width()*0.5-bossbullet[i].m_rect_boss.width()*0.5;
                bossbullet[i].m_y_boss=m_y_boss;
                break;
            }
        }
    }
}




void enemyplane::hpupdate()
{
    hp++;
}
